package offer.secnod;

import listNodePractice.ListNode;

public class Offer22 {

    public ListNode getKthFromEnd(ListNode head, int k) {
        if (head==null)
        {
            return  null;
        }
        ListNode temp=head;
        ListNode m;
        for (int i = 0; i < k; i++) {
            if (temp!=null){
                temp=temp.next;
            }
        }
        m=temp;
        ListNode result=head;

        while (m!=null){
            m=m.next;
            result=result.next;
        }

        return  result;
    }


}
